from py2neo import Graph,Node,Relationship,NodeMatcher,RelationshipMatcher
import json

def connectNeo4j(ip,username,password):
    graph = Graph(ip,username=username,password=password)
    matcher = NodeMatcher(graph)
    rmatcher = RelationshipMatcher(graph)
    
    return graph,matcher,rmatcher

def init_include(data_include):
    for data in data_include:
        print(data)
        src = str(data['startnode'])
        dst = str(data['endnode'])

        nodesrc = matcher.match(fid=src).first()
        nodedst = matcher.match(fid=dst).first()

        includelabel = "include"

        newrelation_symbol2ref = Relationship(nodesrc,includelabel,nodedst)

        graph.create(newrelation_symbol2ref)

if __name__ == "__main__":
    (graph,matcher,rmatcher) = connectNeo4j('http://localhost:7474',"neo4j","123456")
    
    data_include = json.load(open("includeedge.json","r"))
    init_include(data_include)
